<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<script type="text/javascript">
	function goback() {
		history.go(-1);
	}
	$(function() {
		$("#div_search").hide();
	});
	function getUserList() {
		var name = $("#searchText").val().trim();
		if (name == "") {
			return;
		}
		$("#div_search").show();
		$
				.get(
						'user/search/json',
						{
							'searchText' : name
						},
						function(data) {
							if (data && data.success == "true") {
								$("#user_list tbody").html("");
								var rows = $("<tbody></tbody>");
								$
										.each(
												data.data,
												function(n, value) {
													var tr = $("<tr></tr>");
													var selectTd = $(
															"<td id='td_checkbox'></td>")
															.append(
																	"<label class='checkbox'><input type='checkbox' id='userIds' name='userIds' value='"
							+ value.id + "'></label>");
													var usernameTd = $(
															"<td></td>")
															.append(
																	value.username);
													var realnameTd = $(
															"<td></td>")
															.append(
																	value.realname);
													tr.append(selectTd).append(
															usernameTd).append(
															realnameTd)
															.appendTo(rows);
												});
								$("#user_list tbody").html(rows.html());
							}
						}, 'json');
	}
</script>
<div class="page-header">
	<h3 style="margin-top: auto">添加项目类别成员:<a href="javascript:void(0);">${pgroup.cnName}/${pgroup.name}</a></h3>
</div>
<div class="row-fluid">
	<div class="span9">
		<form class="form-horizontal"
			action="<%=request.getContextPath()%>/pgroup/${pgroup.id}/delete_member"
			method="POST" style="margin-left:25px">
			<h4>已添加用户</h4>
			<button type="submit" class="btn" id="submit" style="float: right">
				<i class="icon-remove"></i>&nbsp;删除用户
			</button>
			<table class="table table-hover">
				<thead>
					<tr>
						<th>选择</th>
						<th>用户名</th>
						<th>真实姓名</th>
					</tr>
				</thead>
				<tbody>
					<c:choose>
						<c:when test="${!empty users}">
							<c:forEach items="${users}" var="user" varStatus="s">
								<tr>
									<td><label class="checkbox"><input type="checkbox"
											name="userIds" value="${user.id}"></label></td>
									<td>${user.username}</td>
									<td>${user.realname}</td>
								</tr>
							</c:forEach>
						</c:when>
					</c:choose>
				</tbody>
				<tfoot>
				</tfoot>
			</table>
		</form>
	</div>
	<div class="form-search">
		<div class="input-append">
			<input type="text" class="span1 search-query" id="searchText"
				name="searchText" style="margin-left:25px;width: 400px">
			<button type="button" class="btn"  onclick="getUserList()">
				<i class="icon-search"></i>&nbsp;搜索并添加新用户
			</button>
		</div>
	</div>
	<div class="span9" id="div_search">
		<form class="form-horizontal"
			action="<%=request.getContextPath()%>/pgroup/${pgroup.id}/add_member"
			method="POST">
			<table class="table table-hover" id="user_list">
				<thead>
					<tr>
						<th>选择</th>
						<th>用户名</th>
						<th>真实姓名</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
				<tfoot>
				</tfoot>
			</table>
			<div class="control-group">
				<div class="controls">
					<!-- <button type="button" class="btn" onclick="goback()">
						<i class="icon-remove"></i>&nbsp;取消
					</button> -->
					<button type="submit" class="btn" id="submit" style="float:right">
						<i class="icon-ok"></i>&nbsp;确认添加
					</button>
				</div>
			</div>
		</form>
	</div>
</div>